using UnityEngine;

public class CameraController : MonoBehaviour
{
    [Header("引用")]
    public Transform target;

    [Header("参数")]
    public float distance = 10f;
    public float height = 5f;
    public float smoothSpeed = 0.125f;

    private Vector3 offset;

    private void Start()
    {
        offset = new Vector3(0f, height, -distance);
    }

    private void LateUpdate()
    {
        if (target == null) return;

        // 计算相机目标位置
        Vector3 desiredPosition = target.position + offset;

        // 平滑移动相机
        Vector3 smoothedPosition = Vector3.Lerp(transform.position, desiredPosition, smoothSpeed);
        transform.position = smoothedPosition;

        // 让相机看向目标
        transform.LookAt(target);
    }
}